package com.sample.springbatch.utils;

import java.util.Collection;
import java.util.Iterator;

/**
 * Created by zwg on 2016/10/16.
 */
public class StringUtil {

    /**
     * 基础类型联接成字符串
     * @param delimiter 分隔符
     * @param coll  要联接的基础对象集合
     * @return 字符串
     */
    public static final String join(String delimiter, Collection coll){
        StringBuffer result = new StringBuffer();
        if(coll!=null && coll.size()>0){
            Iterator iterator = coll.iterator();
            while (iterator.hasNext()){
                result.append(String.valueOf(iterator.next()));
                if(iterator.hasNext()){
                    result.append(delimiter);
                }
            }
        }
        return result.toString();
    }

    /**
     * 去掉emoji表情符
     * @param source
     * @return
     */
    public static final String  filterEmoji(String source){
        /*if(source != null)
        {
            Pattern emoji = Pattern.compile ("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",Pattern.UNICODE_CASE | Pattern . CASE_INSENSITIVE ) ;
            Matcher emojiMatcher = emoji.matcher(source);
            if ( emojiMatcher.find())
            {
                source = emojiMatcher.replaceAll("");
                return source ;
            }
            return source;
        }
        return source;*/
        if(null!=source){
            return source.replaceAll("[\ud800\udc00-\udbff\udfff\ud800-\udfff]", "");
        }else{
            return source;
        }
    }

}